package sets.set.treeset;

import sets.collection.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;
/*
如果同时具备比较器和自然排序，会优先按照比较器的规则，进行排序操作
 */
public class TreeSetDemo3 {
    public static void main(String[] args) {
        //匿名内部类方法
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int ageResult = o1.getAge() - o2.getAge();
                return ageResult ==0?o1.getName().compareTo(o2.getName()):ageResult;
            }
        });
        ts.add(new Student("qq",12));
        ts.add(new Student("qqq",13));
        ts.add(new Student("ss",14));
        ts.add(new Student("dd",15));
        System.out.println(ts);
    }
}
